/*************************************************
 *FileName:      notecase.js
 *Description:   我的账户.js
 *Others:        陈灿
 *************************************************/
    /*
     * 启动
     */
    mui.init();
    mui('.mui-scroll-wrapper').scroll({
        indicators: false,      //是否显示滚动条 默认为true
        deceleration: 0.0006,    //阻尼系数,系数越小滑动越灵敏 默认0.0006
        bounce: true           //是否启用回弹 默认true
    });
    mui.init({
        beforeback: function() {
            var list = plus.webview.currentWebview().opener();
            mui.fire(list, 'refreshindex');
            return true;
        }
    });
    /*
     * 变量初始化
     */
    var uid = localStorage.replace_uid;
    var token = localStorage.replace_token;
    var page = 1,page_num=6;
    var isUp = true,amount=1,personal_verify=true;
    /*
     * 主程序
     */ 
    $(document).ready(function() 
    {
        //绑定多个tap跳转页面
          bindTaps(['convert']);            
        //样式加载
        pagecss();
    });
    window.addEventListener('notecase2', function(e){//执行刷新
        location.reload(); 
    });
    /**
     * pagecss
     * 样式加载
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function pagecss(){
        mui.plusReady(money)
        mui.plusReady(list)
//      money();
//      list();
        $('.rou').on('tap',function(){
            $('.poimit-table1').fadeIn();
            $('.promit').css({display:'block'});
        })
        
        $('.promit').on('tap',function(){
            $('.poimit-table1').fadeOut();
            $('.promit').css({display:'none'});
        })
        
        $('.deposit').on('tap',function(){ 
            if(personal_verify){ 
                mui.confirm('您还未完成个人认证，无法提取！','提示',['取消','去完成个人认证'],function(e){
                    e.index == 1 ? common.pageTransition('attestation.html') :null;
                },'div')
            }else{
                common.pageTransition("withdraw.html");
            }
        })
        
    }

    /**
     * money
     * 余额
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function money(){
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/user/myTemporaryBalance",
            dataType:'jsonp',
            data: {uid:uid,token:token},
            success: function(data) {
                if(data.error_code == 0){
                    $('.balance-num').html('<em class="money"></em><span class="balance">'+data.data.temporary_balance+'</span>');
                    $('.link-left-money').text(data.data.withdrawal_balance);
                    $('.poimit-table1 .table-text').html(data.data.agreement);
                    data.data.personal_verify=='1' ?personal_verify=false :personal_verify=true;
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                }
            }  
        });
    }
    
    /**
     * list
     * 账户记录
     * @cc 
     * @DateTime 2018-01-08T06:19:16+0800
     * @param    int        
     * @return   void
     */
    function list(){
        $.ajax({
            type: "post",
            url: DOMAIN_NAME + "/index.php/api/user/temporaryMoneyRecords",
            dataType:'jsonp',
            data: {uid:uid,token:token,page:page,page_num:page_num},
            success: function(data) {
                if(data.error_code == 0){
                    if(data.data.length == page_num){
                        $('.mui-scroll').children('.ys-scroll-btm').html('上拉加载更多');
                        isUp = true;
                    }else{
                        $('.mui-scroll').children('.ys-scroll-btm').html('已经到底了');
                        isUp = false;
                    }
                    $('.mui-scroll').children('.ys-scroll-top').html('下拉刷新数据').attr('style', false);
                    var olist='';
                    for(var i=0 ;i<data.data.length ; i++){
                        var omeny = parseInt(data.data[i].expense) ?'red">-'+ data.data[i].expense : 'blue">+'+data.data[i].income;
                        olist+='<tr class="msg-item"><td class="item-left">'+data.data[i].des+'</td>'
                             +'<td class="item-middle">'+data.data[i].time+'</td><td class="item-right '+omeny+'</td></tr>';
                    }
                    $('.main').append(olist);
                    page++;
                }else if(data.error_code == 1001){
                    setTimeout(function(){
                        exitlogin();
                    },1000);
                }else{
                }
            }
        });
    }
    common.scrollUpDown($('.mui-scroll'),function(index){
        if(index>0&&isUp){
            isUp = false;
            list();
        }else if(index<0){
            $('.main').html('');
            isUp = true;
            page = 1;
            list();
        }else if(index>0 && !isUp){
            $('.mui-scroll').children('.ys-scroll-btm').html('已经到底了');
        }
    });
    
